package xyz.kongbai121.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.kongbai121.demo.domain.Chat;
import xyz.kongbai121.demo.domain.ChatList;
import xyz.kongbai121.demo.domain.RespBean;
import xyz.kongbai121.demo.service.IChatService;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private IChatService chatService;

    @RequestMapping("/deliver")
    public RespBean deliver(String token, String content, Long toUserId){
        String msg = chatService.save(token, content, toUserId);
        return new RespBean(true,msg);
    }

    @RequestMapping("/list")
    public RespBean list(String token){
        List<ChatList> list = chatService.list(token);
        return new RespBean(true,list);
    }

    @RequestMapping("/get")
    public RespBean get(Long fromUserId, String token){
        List<Chat> msg = chatService.get(fromUserId, token);
        return new RespBean(true,msg);
    }
}
